#include<string>
#include<vector>
using namespace std;

int countSubstrings(string s) {
    int n = s.size();
    vector<vector<bool>> dp(n, vector<bool>(n));
    int ret = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        for (int j = i; j < n; j++)
        {
            if (s[i] == s[j])
            {
                if (i == j) dp[i][j] = true;
                else if (i + 1 == j) dp[i][j] = true;
                else dp[i][j] = dp[i + 1][j - 1];
            }
            if (dp[i][j]) ret += 1;
        }
    }
    return ret;
}

string longestPalindrome(string s) {
    int n = s.size();
    vector<vector<bool>> dp(n, vector<bool>(n));
    string ret = "";
    for (int i = n - 1; i >= 0; i--)
    {
        for (int j = i; j < n; j++)
        {
            if (s[i] == s[j])
            {
                if (i == j) dp[i][j] = true;
                else if (i + 1 == j) dp[i][j] = true;
                else dp[i][j] = dp[i + 1][j - 1];
            }
            if (dp[i][j])
                if (j - i + 1 > ret.size())
                    ret = s.substr(i, j - i + 1);
        }
    }
    return ret;
}

int main()
{
    countSubstrings("abc");
    longestPalindrome("abcabc");

	return 0;
}